*******************************************************
** 					REPLICATION MATERIAL 
** 
** "Do Authoritarian Elections Help the Poor? Evidence from Russian Cities"
**
**					   	   by 				 			 	  
**			Quintin H. Beazer & Ora John Reuter
**
**						     in							 	  
** 				The Journal of Politics		 	  
**													 	  
*******************************************************


* File created and checked May 2020 using Stata 14. To ask questions 
* or report a suspected error, please contact the authors. We are happy 
* to correspond with others about the project. Send emails to: 
* Quintin Beazer (qbeazer@fsu.edu) or John Reuter (reutero@uwm.edu) 

* This .do file contains code for reproducing the analyses in the main text.
* Specifically, this code replicated results for Tables 1-5.
  
* Replication code for the appendix analyses appears separately in the 
* accompanying .do file. Code for the plots and sensitivity analysis are
* in the accompanying .R script.



* setting working directory
cd "XXXXX"

* loading housing dataset
use "zhilJOP.dta", clear

* setting control vars
global cvars pressfreedom workpop AvgSalary1 regdem birthrate regprom pop
global lcvars l.pressfreedom l.workpop l.AvgSalary1 l.regdem l.birthrate l.regprom  l.pop

* allow print results without pause
set more off

* gen logged DV
gen lbadzhilpc = log(badzhilpc + 1)

** TABLE 1: Bad Housing Increases under Appointed Mayors
**********************************************************

* Model 1 (Bad housing in 1000 sq m)
xtreg badzhil appointed zhiltot $cvars i.year, fe cluster(city_id)
estimates store mod1_1

* Model 2 (Bad housing in sq m per capita)
xtreg badzhilpc appointed $cvars i.year, fe cluster(city_id)
estimates store mod1_2

* Model 3 (Bad housing in sq m per capita -- logged) 
xtreg lbadzhilpc appointed $cvars i.year, fe cluster(city_id)
estimates store mod1_3

* Model 4 (Bad housing as % of total housing)
xtreg zhilrat appointed $cvars i.year, fe cluster(city_id)
estimates store mod1_4


** Table 1
estout mod1_1 mod1_2 mod1_3 mod1_4, ///
	cells(b( fmt(%9.3f)) se(par)  p(fmt(%9.3f)) ) stats(N r2 bic) style(tex)  



	
** TABLE 2: Elected Mayors Lose Votes when There is More Bad Housing
**************************************************************

use "zhilJOP.dta", clear

* Model 1
xtreg incumvote  l.badzhil l.zhiltot $cvars i.year if munelec==1, fe cluster(city_id)
estimates store mod2_1

* Model 2
xtreg incumvote l.badzhilpc $cvars i.year if munelec==1, fe cluster(city_id)
estimates store mod2_2

** Table 2 presents selected coefficients (full results presented in Table A5):
estout mod2_1 mod2_2, ///
	cells(b( fmt(%9.3f)) se(par)  p(fmt(%9.3f)) ) stats(N r2 bic) style(tex)  



	
** TABLE 3: Delivering United Russia Votes Helps Keep Appointed Mayors in Office
********************************************************************************	

use "zhilJOP.dta", clear

** dropping obs without mayorid & setting mayorid as panel variable
drop if mayorid==.
tsset mayorid year

* Model 1
xtreg turnover  l.URduma l.badzhil l.zhiltot $cvars  i.year if appointed==1, fe cluster(city_id)
estimates store mod3_1

* Model 2
xtreg turnover  l.URlow l.URhigh l.badzhil l.zhiltot $cvars  i.year if appointed==1, fe cluster(city_id)
estimates store mod3_2
	
* Table 3 presents selected coefficients (full results presented in Table A6):
estout mod3_1 mod3_2, ///
	cells(b( fmt(%9.3f)) se(par)  p(fmt(%9.3f)) ) stats(N r2 bic) style(tex)  

	
	
*** Table 4: Bad Housing Increases More under Appointed Mayors
*** Who Can Deliver Strong Electoral Results for United Russia
**************************************************************

use "zhilJOP.dta", clear


** Model 1: city-specific UR vote share (continuous measure)
xtreg badzhil appointed l.URduma lURdumaXapp zhiltot $cvars i.year, fe cluster(city_id)
estimates store mod4_1

** Model 2: city-specific UR vote share (binary measure)
xtreg badzhil appointed l.URhigh lURhighXapp zhiltot $cvars i.year, fe cluster(city_id)
estimates store mod4_2

** Model 3: mayor-specific UR vote share (continuous measure)
xtreg badzhil appointed URduma2 URduma2Xapp zhiltot $cvars i.year, fe cluster(city_id)
estimates store mod4_3

** Model 4: mayor-specific UR vote share (binary measure)
xtreg badzhil appointed highUR2 highUR2Xapp zhiltot $cvars i.year, fe cluster(city_id) 
estimates store mod4_4

** Table 4 presents selected coefficients (full results presented in Table A10): 
estout mod4_1 mod4_2 mod4_3 mod4_4, ///
	cells(b( fmt(%9.3f)) se(par)  p(fmt(%9.3f)) ) stats(N r2 bic) style(tex) 


** Note: plots for the interaction term made with accompanying R script
	

	
	
*** TABLE 5: Additional Tests Provide No Support for Rival Explanations
***********************************************************************
	
** Models 1 & 2: Entropy Balancing

use "zhilJOP.dta", clear

* keeping only: 1.) elected observations for cities that switch, and
* 2.) obs for cities that never give up elections

by city_id: egen always = min(appointed)
replace always = . if appcity==.

keep if appointed==0 | always==1
* robust to dropping drop "always elections" cities, but loses observations

keep badzhil badzhilpc zhiltot city_id year appcity $cvars civsoc91 republic pctRussian ///
diff_unemp unemployrate margin ///
URduma URduma07 URduma11 

by city_id: egen appcityM = max(appcity)
by city_id: egen civsoc = max(civsoc91)
by city_id: egen repub = max(republic)
by city_id: egen pRus = max(pctRussian)
by city_id: egen popM = mean(pop)
by city_id: egen lpopM = mean(log(pop+1))
by city_id: egen pressM = mean(pressfreedom)
by city_id: egen workpopM = mean(workpop)
by city_id: egen avgM = mean(AvgSalary1)
by city_id: egen demM = mean(regdem)
by city_id: egen birthM = mean(birthrate)
by city_id: egen propM = mean(regprom)
by city_id: egen diffM = mean(diff_unemp)
by city_id: egen unempM = mean(unemployrate)
by city_id: egen marginM = mean(margin)
by city_id: egen URdumaM = mean(URduma)
by city_id: egen badzhilM = mean(badzhil)
by city_id: egen badzhilpcM = mean(badzhilpc)
by city_id: egen zhiltotM = mean(zhiltot)

drop appcity civsoc91 republic pctRussian pop ///
pressfreedom workpop AvgSalary1 regdem birthrate regprom ///
diff_unemp unemployrate badzhil badzhilpc zhiltot

collapse (max) appcityM pressM workpopM avgM demM birthM propM ///
civsoc repub pRus popM diffM unempM marginM URdumaM ///
URduma07 URduma11 ///
badzhilM badzhilpcM zhiltotM, by(city_id)

* using averaged UR results
ebalance appcityM pressM workpopM avgM demM birthM propM ///
civsoc repub pRus popM ///
badzhilM badzhilpcM zhiltotM ///
 unempM  URdumaM, gen(avgduma)
 
label var avgduma "Ebal weights, averaged Duma elections" 

* using UR results for separate elections (not reported to save space)
ebalance appcityM pressM workpopM avgM demM birthM propM ///
civsoc repub pRus popM ///
badzhilM badzhilpcM zhiltotM ///
 unempM  /// 
URduma07 URduma11, gen(avgduma2)

label var avgduma2 "Ebal weights, separating 07/11 Duma elections"

keep city_id avgduma avgduma2 
sort city_id
save "ebavg.dta", replace



** merge back together

use "zhilJOP.dta", clear
tsset city_id year 
sort city_id year
merge city_id using "ebavg.dta"
drop _merge
sort city_id year


** estimate models with entropy weights

* Model 1
xtreg badzhil appointed zhiltot $cvars i.year [aweight = avgduma], fe cluster(city_id) 
estimates store mod5_1

* alt model: DV = bad housing per capita (not reported to save space)
xtreg badzhilpc appointed $cvars i.year [aweight = avgduma], fe cluster(city_id) 
estimates store mod5_alt1

* Model 2
xtreg badzhil appointed l.URduma lURdumaXapp zhiltot $cvars i.year [aweight = avgduma], fe cluster(city_id)
estimates store mod5_2

* alt model: binary measure of UR vote delivery (not reported to save space)
xtreg badzhil appointed l.URhigh lURhighXapp zhiltot $cvars i.year [aweight = avgduma], fe cluster(city_id) 
estimates store mod5_alt2

* alt model: DV = bad housing per capita (not reported to save space)
xtreg badzhilpc appointed l.URduma lURdumaXapp zhiltot $cvars i.year [aweight = avgduma], fe cluster(city_id)
estimates store mod5_alt3



** Models 3 & 4: Placebo Tests Comparing Appointed Cities during Pre-appointment Period (no FE)

sort city_id year
global xcvars republic civsoc91 kavkaz pctRussian /* extra time-invariant covariates*/

by city_id: gen lURdumaXappcity = l.URduma*appcity
gen URduma2Xappcity = URduma2*appcity

* Model 3
reg badzhil appcity zhiltot $cvars $xcvars i.year if appointed==0, cluster(city_id)
estimates store mod5_3

* Model 4
reg badzhil appcity l.URduma lURdumaXappcity zhiltot $cvars $xcvars i.year if  appointed==0, cluster(city_id)
estimates store mod5_4

* alt models: DV = bad housing per capita (not reported to save space)
reg badzhilpc appcity $cvars $xcvars i.year if appointed==0, cluster(city_id)
estimates store mod5_alt4

reg badzhilpc appcity l.URduma lURdumaXappcity $cvars $xcvars i.year if appointed==0, cluster(city_id)
estimates store mod5_alt5


** Table 5 presents selected coefficients (full results presented in Table A13):
estout mod5_1 mod5_2 mod5_3 mod5_4, ///
	cells(b( fmt(%9.3f)) se(par)  p(fmt(%9.3f)) ) stats(N r2 bic) style(tex)

	
	
	



	
	
	
